import {actionTypes} from './index'
import http from "@/http";
import {message} from 'antd'
import axios from 'axios'
export const changeLoginStatus = (value)=>({
    type: actionTypes.CHANG_LOGIN_STATUS,
    value
});

export const login = (values)=>{
   return (dispatch)=>{
       console.log(999)
       http.ajax({
           url: '/login/userLogin',
           method: 'post',
           params: {
               userName: values.username,
               password: values.password
           },
           showLoading: false
       }).then((res) => {
           console.log(res)
           if (res.status === 1) {
               localStorage.setItem('loginStatus', 'true')
               console.log(axios.defaults.headers)
               // axios.defaults.headers.cookie.cg_session = res.data.sessionId;
               dispatch(changeLoginStatus(true))
               dispatch(changeButtonStatus(false))
               message.info('登录成功!');
           } else {
               dispatch(changeButtonStatus(false))
               message.error('用户名或者密码错误!')
           }
       }).catch((err) => {

           message.error(err)
           dispatch(changeButtonStatus(false))
       })
   }
};

export const changeButtonStatus = (value) =>({
    type: actionTypes.CHANGE_BUTTON_STATUS,
    value
})


